﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using ThreeByte.ActiveDeck.Data;

namespace ActiveDeckPublishInstaller
{
    class Program
    {
        static void Main(string[] args) {
            //Grab the file name from the command line
            if(args.Length != 1) {
                Console.WriteLine("Please provide a filename to publish");
                Environment.Exit(-1);
            }
            try {
                FileInfo fileToPublish = new FileInfo(args[0]);
                //Parse the last part of the name (filename)
                string INSTALLER_NAME = fileToPublish.Name;

                FileVersionInfo info = FileVersionInfo.GetVersionInfo(fileToPublish.FullName);
                Version ver = Version.Parse(info.ProductVersion);
                string downloadName = string.Format("{0}/{1}", ver, INSTALLER_NAME);
                CloudHelper.SegmentAndStoreDownload("installers/beta", downloadName, File.ReadAllBytes(fileToPublish.FullName), "exe");
                DataUtil.SetConfigValue("AddInVersion_Beta", ver.ToString());
                DataUtil.SetConfigValue("AddInUpdated_Beta", DateTime.Now.ToString());
                return;
            } catch(Exception ex) {
                Console.WriteLine("Error: {0}", ex);
                Environment.Exit(-1);
            }
        }
    }
}
